package com.hk.controller.admin;

import com.hk.model.pojo.Activity;
import com.hk.model.vo.ActivityVo;

import com.hk.result.Result;
import com.hk.service.ActivityService;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/clues/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 获取活动列表
     *
     * @return
     */
    @GetMapping("/list")
    public ActivityVo getActivityList(@RequestParam Integer pageNum, @RequestParam Integer pageSize,
                                      @RequestParam(required = false) Integer code
            , @RequestParam(required = false) Data beginCreateTime, @RequestParam(required = false) Data endCreateTime,
                                      @RequestParam(required = false) Data beginTime, @RequestParam(required = false) Data endTime) {
        ActivityVo activityVo = activityService.getActivityList(pageNum, pageSize, code, beginCreateTime, endCreateTime, beginTime, endTime);

        return activityVo;
    }

    /**
     * 添加活动信息
     * @param activity
     * @return
     */
    @PostMapping
    public Result addActivity( @RequestBody Activity activity) {
        activityService.addActivity(activity);
        return Result.success();
    }

    /**
     * 删除活动信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteActivity(@PathVariable Integer id) {
        log.info("删除活动信息{}",id);
        activityService.deleteById(id);
        return Result.success();
    }


    @ApiOperation(value = "获取活动id")
    @GetMapping("/{id}")
    public Result getId(@PathVariable Integer id){
        log.info("获取活动id{}",id);
      Activity activity=  activityService.getId(id);
      return Result.success(activity);
    }
    @ApiOperation(value = "修改活动信息")
    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        activityService.updateActivity(activity);
        return Result.success();
    }
}
